<!DOCTYPE html>
<html>
<body>
<input id="str" placeholder="输入字符串">
<input id="index" type="number" placeholder="输入数字" min="1">
<button onclick="output()">获取字符</button>
<p id="result"></p>

<script>
function output() {
  const s = document.getElementById("str").value;
  const i = parseInt(document.getElementById("index").value);
  document.getElementById("result").innerText = s[i-1] || "无效位置";
}
</script>
</body>
</html>